import React, { FC } from 'react'
import classNames from 'classnames';
import './style.scss';

interface ImageProps {
  src: string;
  alt?: string;
  lazy?: boolean;
  onClick?: () => void;
  width?: number | string;
  height?: string | number;
  round?: boolean
}

function imageLoad (src:string) {
  return new Promise((resolve, reject) => {
    const img =  new Image()
    img.onload = function() {
      resolve(true)
    }
    img.onerror = function() {
      reject(false)
    }
    img.src = src;
  })
}

const ImageView:FC<ImageProps> = (props) => {
  const {width,height,round, src, alt, onClick, ...rest} = props;
  const classes = classNames('img-wrapper', {
    'img-wrapper-round': round
  })
  return <div
    style={{width,height}}
    className={classes}
    onClick={onClick}>
    <img src={src}  {...rest} alt={alt}/>
  </div>
}

// 默认信息
ImageView.defaultProps = {
  alt: '提示信息',
  width: '4.32rem',
  height: '3.24rem',
  round: false,
  src: 'avatar.jpeg'
}

export default ImageView;
